import UIKit

extension NSArray {
    
    /**
     过滤某些值
     - parameter searchText: 搜索的值
     - parameter filters:    过滤的字段
     
     - returns: 过滤过后的结果
     */
    func filter(searchText: String, filters: String...) -> NSArray {
        let substitutionVariables = ["QUERY": searchText]
        var format = ""
        
        for filter in filters {
            format = format + "(SELF." + filter + " CONTAINS[cd] $QUERY) "
            if filter != filters.last {
                 format = format + "OR "
            }
        }
        let predicate = NSPredicate(format: format).predicateWithSubstitutionVariables(substitutionVariables)

        return filteredArrayUsingPredicate(predicate)
    }
}